import swaggerJsdoc from "swagger-jsdoc";
import swaggerUi from "swagger-ui-express";
import { fileURLToPath } from "url";
import { dirname, join } from "path";

// 获取当前文件的目录路径
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const options = {
  definition: {
    openapi: "3.0.0",
    info: {
      title: "大学选择推荐系统 API",
      version: "1.0.0",
      description: "大学选择推荐系统的 API 文档",
    },
    servers: [
      {
        url: "http://localhost:3000",
        description: "开发服务器",
      },
    ],
  },
  // 指定 API 路由文件的位置
  apis: [
    join(__dirname, "../routes/**/*.mjs"), // 包含所有子目录
  ],
};

const specs = swaggerJsdoc(options);

export default function swaggerInstall(app) {
  app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(specs));
}
